package com.jia.train.seat.controller;

import com.jia.train.global.page.PageResponse;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.seat.request.DailyTripsQueryRequest;
import com.jia.train.seat.request.DailyTripsSaveRequest;
import com.jia.train.seat.response.DailyTripsQueryResponse;
import com.jia.train.seat.response.DailyTripsSaveResponse;
import com.jia.train.seat.service.DailyTripsService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/daily/trips")
public class DailyTripsController {

    @Resource
    private DailyTripsService dailyTripsService;

    @PostMapping("/insert")
    public BaseResponse<DailyTripsSaveResponse> insertDailyTrips(@Valid @RequestBody DailyTripsSaveRequest request) {
        DailyTripsSaveResponse response = dailyTripsService.insert(request);
        return new BaseResponse<>(response);
    }

    @GetMapping("/query")
    public BaseResponse<PageResponse<DailyTripsQueryResponse>> query(@Valid DailyTripsQueryRequest request) {
        PageResponse<DailyTripsQueryResponse> responseList = dailyTripsService.selectPage(request);
        return new BaseResponse<>(responseList);
    }

    @GetMapping("/list")
    public BaseResponse<List<DailyTripsQueryResponse>> query() {
        List<DailyTripsQueryResponse> responseList = dailyTripsService.selectList();
        return new BaseResponse<>(responseList);
    }

    @DeleteMapping("/delete/{id}")
    public BaseResponse<String> delete(@PathVariable Long id) {
        dailyTripsService.deleteDailyTrips(id);
        return new BaseResponse<>("success");
    }

    @PostMapping("/gen-daily/{date}")
    public BaseResponse<String> genDailyTrip(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {
        dailyTripsService.genDailyTrip(date);
        return new BaseResponse<>("success");
    }


}
